package org.karelun.gef.actions;

import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.PartInitException;
import org.karelun.gef.editors.DiagramEditorInput;
import org.karelun.gef.helper.ConstantMessages;
import org.karelun.gef.helper.IDConstant;
import org.karelun.gef.helper.ImageResource;

public class CreateSateEditorAction extends Action {

	private IWorkbenchWindow window;

	public CreateSateEditorAction(IWorkbenchWindow window) {
		this.window = window;
		setId(IDConstant.StateEditACtion_Id);
		setActionDefinitionId(IDConstant.StateEditACtion_CMD_ID);
		setText(ConstantMessages.stateEditor_Text);
		setToolTipText(ConstantMessages.stateEditor_ToolTip);
		ImageDescriptor imageDes = ImageResource.getImageDesc(ImageResource.NEW_STATEDIAGRAM_ACTION);
		setImageDescriptor(imageDes);
	}

	@Override
	public void run() {
		IPath path = Platform.getLocation();
		IEditorInput input =new DiagramEditorInput(path);
		IWorkbenchPage page = window.getActivePage();
		try {
			page.openEditor(input, IDConstant.StateDiagramEditor_Id);
		} catch (PartInitException e) {
			e.printStackTrace();
		}
	}
}
